package com.examsystem.controller;

import com.alibaba.fastjson.JSON;
import com.examsystem.pojo.vo.LoginUser;
import com.examsystem.service.UserPaperService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import static com.examsystem.Const.ConstMsg.SUBMIT_SUCCESS_MSG;


/**
 * @author fire'ge
 */
@Controller
public class UserPaperController {
    @Resource
    private UserPaperService userPaperService;

    /*
    学生端代码
     */

    /**
     * 手动提交试卷的接口
     * @return 返回提交成功的信息
     */
//    @PreAuthorize("hasAuthority('student')")

    @ResponseBody
    @RequestMapping(value = "/userPaper/confirmFinish",produces = "application/json;charset=utf-8")
    public String confirmFinish() {
        LoginUser user = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        int userId = user.getUser().getUserId();
        userPaperService.updateUserPaper(userId);
       return JSON.toJSONString(SUBMIT_SUCCESS_MSG);

    }

}
